package com.realdolmen.whiteyellowcross.model;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class WaitMonthPlanning {

	private Long year;
	private Long month;
	Map<Integer, List<WaitWorkShiftDayPlan>> waitWorkShiftDayPlanning = new TreeMap<Integer, List<WaitWorkShiftDayPlan>>();

	public WaitMonthPlanning(Long year, Long month) {
		this.year = year;
		this.month = month;
	}

	public Map<Integer, List<WaitWorkShiftDayPlan>> getWaitWorkShiftDayPlannings() {
		return waitWorkShiftDayPlanning;
	}

	public List<WaitWorkShiftDayPlan> getWaitWorkShiftDayPlanning(Integer day) {
		List<WaitWorkShiftDayPlan> workShiftPlanList = waitWorkShiftDayPlanning.get(day);
		return workShiftPlanList;
	}

	public void addWaitDayPlanning(Integer day,List<WaitWorkShiftDayPlan> waitWorkShiftPlan){
		waitWorkShiftDayPlanning.put(day, waitWorkShiftPlan);
	}

	public Long getYear() {
		return year;
	}

	public void setYear(Long year) {
		this.year = year;
	}

	public Long getMonth() {
		return month;
	}

	public void setMonth(Long month) {
		this.month = month;
	}
	
	public Map<Personel,Integer> getPersonelMonthTotals(){
		Map<Personel,Integer> personelTotals =new HashMap<Personel,Integer>();
		Collection<List<WaitWorkShiftDayPlan>> waitMonthWorkShiftPlan = waitWorkShiftDayPlanning.values();
		for (List<WaitWorkShiftDayPlan> waitDayWorkShiftPlan:waitMonthWorkShiftPlan){
			for (WaitWorkShiftDayPlan waitWorkShiftPlan :waitDayWorkShiftPlan){
				Personel personel = waitWorkShiftPlan.getPersonel();
				if (personelTotals.containsKey(personel)){
					int total = personelTotals.get(personel);
					total = total + waitWorkShiftPlan.getWorkShift().getHours().intValue();
					personelTotals.put(personel,total);
				}else{
					personelTotals.put(personel, 1*waitWorkShiftPlan.getWorkShift().getHours().intValue());
				}
			}
		}
		return personelTotals;
		
	}
	
	public Set<Personel> getStandbyPersonel(){
		
		Set<Personel> personelList = new HashSet<Personel>();
		
		Collection<List<WaitWorkShiftDayPlan>> waitMonthWorkShiftPlan = waitWorkShiftDayPlanning.values();
		for (List<WaitWorkShiftDayPlan> waitDayWorkShiftPlan:waitMonthWorkShiftPlan){
			for (WaitWorkShiftDayPlan waitWorkShiftPlan :waitDayWorkShiftPlan){
				Personel personel = waitWorkShiftPlan.getPersonel();
				personelList.add(personel);
			}
		}
		return personelList;
	}
	
	

	@Override
	public String toString() {
		return waitWorkShiftDayPlanning.toString();

	}

}
